//
//package com.example.mybatisplus.web.controller;
//
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.example.mybatisplus.model.domain.Business;
//import com.example.mybatisplus.model.dto.PageDTO;
//import com.example.mybatisplus.service.BusinessService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import com.example.mybatisplus.common.JsonResponse;
//
//@RestController
//@RequestMapping("/api/business")
//public class BusinessController {
//    @Autowired
//    private BusinessService businessService;
//
//    @GetMapping("pageList")
//    public JsonResponse pageList(@RequestParam(value = "sortByDistance", defaultValue = "false") boolean sortByDistance,
//                                 @RequestParam(value = "sortByStars", defaultValue = "false") boolean sortByStars,
//                                 Business business, PageDTO dto) {
//        Page<Business> page = businessService.pageList(business, dto, sortByDistance, sortByStars);
//        return JsonResponse.success(page);
//    }
//}
package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.Business;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.mybatisplus.common.JsonResponse;

@RestController
@RequestMapping("/api/business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @GetMapping("pageList")
    public JsonResponse pageList(
            @RequestParam(value = "sortByDistance", defaultValue = "false") boolean sortByDistance,
            @RequestParam(value = "sortByStars", defaultValue = "false") boolean sortByStars,
            @RequestParam(value = "distance", required = false) Float distance,
            @RequestParam(value = "stars", required = false) Float stars,
            @RequestParam(value = "additionalFilters", required = false) String additionalFilters,
            @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        // 创建 PageDTO 对象并设置分页参数
        PageDTO dto = new PageDTO();
        dto.setPageNo(pageNo);
        dto.setPageSize(pageSize);
        dto.setDistance(distance);
        dto.setStars(stars);
        dto.setAdditionalFilters(additionalFilters); // 设置设施筛选条件

        // 调用业务层方法
        Page<Business> page = businessService.pageList(new Business(), dto, sortByDistance, sortByStars);

        // 返回响应
        return JsonResponse.success(page);
    }
}
